package Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Bean.Course;
import Dao.CourseDao;

public class ShowAllCourseServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		ArrayList courseList = new ArrayList();
		CourseDao courseDao = new CourseDao();
		ServletContext application=this.getServletContext();
		try {
			courseList = courseDao.queryAllCourse();
			request.setAttribute("courseList", courseList);
			application.getRequestDispatcher("/showAllCourse.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String cid = request.getParameter("cid");
		Course course = new Course(); 
		CourseDao courseDao = new CourseDao();
		ServletContext application=this.getServletContext();
		try {
			course = courseDao.queryCourseByCid(cid);
			ArrayList courseList = new ArrayList();
			courseList.add(course);
			request.setAttribute("courseList", courseList);
			application.getRequestDispatcher("/showAllCourse.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	

}
